package xyz.scootaloo.oj.leetcode

import org.junit.Test

/**
 * @author flutterdash@qq.com
 * @since 2021/4/7 13:52
 */
class P401 {

    private fun readBinaryWatch(num: Int): List<String> {
        fun count(num: Int): Int {
            var count = 0
            var realNumber = num
            while (realNumber > 0) {
                count += realNumber.and(1)
                realNumber = realNumber.ushr(1)
            }
            return count
        }

        val res = mutableListOf<String>()
        for (hour in 0 until 12) {
            for (minute in 0 until 60) {
                if (count(hour) + count(minute) == num) {
                    res.add("""$hour:${if (minute > 9) minute else "0$minute"}""")
                }
            }
        }
        return res
    }

    @Test
    fun test0() {
        println(readBinaryWatch(1))
        println(readBinaryWatch(5))
    }

}
